package com.ruicar.afs.cloud.manage.common.util;

import com.ruicar.afs.cloud.common.core.uid.AfsSequenceGenerator;
import com.ruicar.afs.cloud.common.core.util.SpringContextHolder;
import com.ruicar.afs.cloud.common.modules.contract.enums.ContractBusinessEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * @author: Lee
 * @date: 2020/5/11 19:39
 * @description: 合同系统生成案件编号
 */
@Slf4j
public class CreatCaseNoUtil {
    /**
     * 生成案件编号
     * @return
     * @param contractBusiness 业务类型枚举值
     */
    public static String GeneratorCaseNo(ContractBusinessEnum contractBusiness) {

        AfsSequenceGenerator afsSequenceGenerator = SpringContextHolder.getBean(AfsSequenceGenerator.class);

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMM");
        Long seqNo = afsSequenceGenerator.genNext(ChineseCharToEnUtil.getAllFirstLetter(contractBusiness.getDesc()),
                dateFormat.format(Calendar.getInstance().getTime()));
        String seqStr = StringUtils.leftPad(seqNo.toString(), 4, "0");
        String caseNo = ChineseCharToEnUtil.getAllFirstLetter(contractBusiness.getDesc())
                + dateFormat.format(Calendar.getInstance().getTime()) + seqStr;
        return caseNo;
    }
}
